package org.baicaix.utils {
	import flash.net.URLLoaderDataFormat;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	/**
	 * 读取文件的工具类
	 * @author dengyang
	 */
	public class LoadFileUtil {
		
		public static function load(path : String, callback : Function, dateFormat : String = URLLoaderDataFormat.TEXT) : void {
			var request : URLRequest = new URLRequest(path);
			var loader : URLLoader = new URLLoader();
			loader.dataFormat = dateFormat;
            
			try {
				loader.load(request);
			} catch (error : SecurityError) {
				trace("A SecurityError has occurred.");
			}

			loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
			loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
			
			function loaderCompleteHandler(event : Event) : void {
				callback(loader.data);
			}
	
			function errorHandler(e : IOErrorEvent) : void {
			}
		}
	}
}
